package club.janna.rpcdemo.codec;

import club.janna.rpcdemo.domain.ServiceInfo;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Component
public class CodecProvider {

    private final Map<ServiceInfo.Protocol, Codec> codecMap = new HashMap<>();

    @PostConstruct
    public void init() {
        codecMap.put(ServiceInfo.Protocol.JAVA_SERIAL, new JavaSerialCodec());
    }

    public Codec get(ServiceInfo.Protocol protocol) {
        return codecMap.get(protocol);
    }
}
